package com.game.server.message.proto.execute;

import java.util.ArrayList;
import java.util.Collection;

import com.comm.ISession;
import com.game.majiang.config.LogManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicPlayer;
import com.game.majiang.logic.LogicServer;
import com.game.majiang.logic.LogicTable;
import com.game.server.message.proto.in.AbstractGetWatchWarPlayerInfoReq;
import com.game.server.message.proto.out.GetWatchWarPlayerInfoRsp;
import com.game.server.message.proto.out.WatchWarPlayerInfoStructrue;
import com.game.server.system.AbstractPlayer;

public class GetWatchWarPlayerInfoReq extends AbstractGetWatchWarPlayerInfoReq {

    @Override
    public void Execute(ISession session) {
		LogManager.getInstance().Log("GetWatchWarPlayerInfoReq");
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
        	LogicTable table = (LogicTable) client.getTable();
            if(table != null) {
            	ArrayList<WatchWarPlayerInfoStructrue> listWWPI = new ArrayList<WatchWarPlayerInfoStructrue>();
            	Collection<AbstractPlayer> players = table.getWatchWar().getPlayers();
            	for (AbstractPlayer abPlayer : players) {
            		LogicPlayer tempPlayer = (LogicPlayer) abPlayer;
            		LogicClient tempClient = (LogicClient) abPlayer.getClient();
            		WatchWarPlayerInfoStructrue wwpi = new WatchWarPlayerInfoStructrue();
            		wwpi.setHead(tempClient.getVo().getHead());
            		wwpi.setName(tempClient.getVo().getNickName());
            		wwpi.setUid(tempClient.getUserId());
            		wwpi.setSeatNo(tempPlayer.getSeatNo() < 1 ? 0 : tempPlayer.getSeatNo());
            		listWWPI.add(wwpi);
				}
            	GetWatchWarPlayerInfoRsp rsp = new GetWatchWarPlayerInfoRsp();
            	rsp.setWwpis(listWWPI.toArray(new WatchWarPlayerInfoStructrue[listWWPI.size()]));
				LogManager.getInstance().Log("监听房间："+rsp);
            	client.Send(rsp);
            }
        }
    }

}
